#include <math.h>
#include <stdio.h>
#include "report.h"
#include "gaussian.h"


int main(int argc, char ** argv)
{
  UnivarGaussian_t uni;
  Report_Real_t stats;
  double avg, sd;
  int i;
  double sum;
  double x;
  
  UnivarGaussian_Init_Params(&uni, 1, 4.0); /* decimal points are critical */
  
  Report_Real_Init(&stats);
  
  for (i=0; i<100000; i++)
  {
    Report_Real_Update(&stats, UnivarGaussian_Sample(&uni, 1, 12.5));
  }

  Report_Real_Compute(&stats, &avg, &sd);

  if (fabs(avg - 12.5) > .1)
    return 1;
  
  if (fabs(sd - 2) > 1e-3)
    return 2;

  sum = 0;
  for (x=0; x<=30; x += .01)
  {
    sum += exp(UnivarGaussian_LogProb(&uni, x, 1, 12.5)) * .01;
  }
  
  if (fabs(sum - 1) > 1e-3)
  {
    printf("cum dist=%.4f\n", sum);
    return 1;
  }

  sum = 0;
  for (x=0; x<=30; x += .01)
  {
    sum += UnivarGaussian_Prob(&uni, x, 1, 12.5) * .01;
  }
  
  if (fabs(sum - 1) > 1e-3)
  {
    printf("cum dist=%.4f\n", sum);
    return 2;
  }

  return 0;
}

